import trinity
import blue
from actorfactory.ActorFactory import RegisterFactory
from actorfactory.ActorFactory import BaseActorFactory
BUILDING = 'BUILDING'

class BuildingFactory(BaseActorFactory):

    def __init__(self):
        BaseActorFactory.__init__(self)



    def Register(self, factoryList):
        factoryList[BUILDING] = self



    def CreateObject(self, template, vPos, vForward, vNorm, properties):
        if (template.GetClassType() == BUILDING):
            building = trinity.WodBuilding()
            building.buildingResPath = str(blue.rot.FilenameToPath(template.GetRes()))
            if (building.buildingRes == None):
                return 
            building.transform = self.HandleScale(template, building.transform)
            building.transform = self.HandleAlignmentForward(template, building.transform, vForward)
            building.transform = self.HandlePosition(template, building.transform, vPos)
            self.HandleProperties(building, properties)
            return building



    def AddToScene(self, scene, obj, template):
        if (template.GetClassType() == BUILDING):
            scene.city.AddBuildingToScene(obj)
            return True
        else:
            return False



    def IsSelfCleaning(self):
        return True



    def RemoveFromScene(self, scene, obj, template):
        if (template.GetClassType() == BUILDING):
            scene.city.RemoveBuildingFromScene(obj)
            return True
        else:
            return False



RegisterFactory(BuildingFactory())

